import java.sql.*;

public class ProcessingBatchStudy {
    private static Connection s_pConnect;
    private static Statement s_pStatement;
    private static Savepoint s_pSavePoint;

    public static void main(String[] args) {
        try {
            Class.forName(Const.JDBC_DRIVER);
            s_pConnect = DriverManager.getConnection(Const.MYSQL_URL, Const.USER_NAME, Const.USER_PASSWORD);
            boolean bSupport = s_pConnect.getMetaData().supportsBatchUpdates();
            if (bSupport) {
                System.out.println("支持批量处理");
            } else {
                System.out.println("不支持批量处理");
                return;
            }

            s_pStatement = s_pConnect.createStatement();
            String strSql1 = "INSERT INTO simpleTable VALUES(NULL , '老王', 40, '打牌')";
            String strSql2 = "INSERT INTO simpleTable VALUES(NULL , '老谢', 42, '抽烟')";
            s_pStatement.addBatch(strSql1);
            s_pStatement.addBatch(strSql2);
            int[] count = s_pStatement.executeBatch();
            for (int i = 0; i < count.length; i ++) {
                System.out.println(count[i]);
            }

        } catch (Exception e2) {
            e2.printStackTrace();

        } finally {
            try {
                if (s_pStatement != null) {
                    s_pStatement.close();
                }

                if (s_pConnect != null) {
                    s_pConnect.close();
                }
            } catch (Exception e) {

            }
        }
    }
}
